package org.codegallery.javagal.grizzly;
import com.sun.grizzly.SSLConfig;
import com.sun.grizzly.http.embed.GrizzlyWebServer;
import com.sun.grizzly.util.LoggerUtils;

import java.util.logging.Level;
import java.util.logging.Logger;



/**
 * User: wenwei
 * Date: 12/29/11
 * Time: 2:38 PM
 */
public class GrizzlyTest {
    public static void main(String[] args) throws Exception {
    	System.setProperty("javax.net.debug", "ssl");
        Logger grizzlyLog=LoggerUtils.getLogger();
        grizzlyLog.setLevel(Level.FINE);
        
//        Logger log = Logger.getLogger("mylogger");
//        log.setLevel(Level.FINE);
//        log.info("program starting......");
        //Logger logger=Logger.getLogger("grizzly");
        GrizzlyWebServer server = new GrizzlyWebServer(8888, "D:\\wamp\\www", true);

        SSLConfig sslConfig=getSSLConfig1();
        server.setSSLConfig(sslConfig);
        server.start();
//        log.info("grizzly server starting......");

    }

    public static SSLConfig getSSLConfig1(){
        SSLConfig sslConfig = new SSLConfig();

        //sslConfig.setNeedClientAuth(this.needClientAuth);
        //sslConfig.setWantClientAuth(this.wantClientAuth);
        //sslConfig.setSecurityProtocol(this.securityProtocol);
        //sslConfig.setKeyManagerFactoryAlgorithm(this.keyManagerFactoryAlgorithm);
        sslConfig.setKeyStoreFile("C:/certworks/exchdmzserver.key");
        //sslConfig.setKeyStoreFile("C:/certworks/eckeystore");
        
        sslConfig.setKeyStorePass("password1");
        //sslConfig.setKeyStoreProvider(this.keyStoreProvider);
        //sslConfig.setKeyStoreType(this.keyStoreType);
        sslConfig.setKeyPass("password1");
        //sslConfig.setTrustManagerFactoryAlgorithm(this.trustManagerFactoryAlgorithm);
        //EmbeddedHttpServer_Grizzly_TrustStoreFile = C:/certworks/exchdmzserverTrustStore.key

        sslConfig.setTrustStoreFile("C:/certworks/exchdmzserverTrustStore.key");
        sslConfig.setTrustStorePass("password1");
        //sslConfig.setTrustStoreProvider(this.trustStoreProvider);
        //sslConfig.setTrustStoreType(this.trustStoreType);
        return sslConfig;
    }

    public static SSLConfig getSSLConfig2(){
        SSLConfig sslConfig = new SSLConfig();

        //sslConfig.setNeedClientAuth(this.needClientAuth);
        //sslConfig.setWantClientAuth(this.wantClientAuth);
        //sslConfig.setSecurityProtocol(this.securityProtocol);
        //sslConfig.setKeyManagerFactoryAlgorithm(this.keyManagerFactoryAlgorithm);
        sslConfig.setKeyStoreFile("C:/certworks/local/localecdmzserver.key");
        sslConfig.setKeyStorePass("password1");
        //sslConfig.setKeyStoreProvider(this.keyStoreProvider);
        //sslConfig.setKeyStoreType(this.keyStoreType);
        sslConfig.setKeyPass("password1");
        //sslConfig.setTrustManagerFactoryAlgorithm(this.trustManagerFactoryAlgorithm);
        sslConfig.setTrustStoreFile("C:/certworks/local/localecdmzserverTrustStore.key");
        sslConfig.setTrustStorePass("password1");
        //sslConfig.setTrustStoreProvider(this.trustStoreProvider);
        //sslConfig.setTrustStoreType(this.trustStoreType);
        return sslConfig;
    }
}
